/*
 * Copyright (c) 2012 Universidad Antonio de Nebrija.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0
 * which accompanies this distribution, and is available at
 * http://www.apache.org/licenses/LICENSE-2.0.html
 * 
 * Contributors:
 *    Universidad Antonio de Nebrija - initial API, implementation and documentation
 */
package com.nebrija.riif.model;

/**
 * Represents an operator for the assertion expression
 * @author asanchep
 *
 */
public enum AssertOperator {
	EQUAL, GREATER, LESS, GREATER_EQUAL, LESS_EQUAL, DISTINCT, TRUE, FALSE;
	
	/**
	 * Convert a text into the corresponding operator
	 * @param info text to be parsed (e.g. ">")
	 * @return
	 */
	public static AssertOperator convert(String info){
		AssertOperator result = AssertOperator.TRUE;
		if(info.equals(">")){
			result = AssertOperator.GREATER;
		}else if (info.equals("<")){
			result = AssertOperator.LESS;
		}else if (info.equals("=")){
			result = AssertOperator.EQUAL;
		}else if (info.equals("<>") || info.equals("!=")){
			result = AssertOperator.DISTINCT;
		}else if (info.equals(">=")){
			result = AssertOperator.GREATER_EQUAL;
		}else if (info.equals("<=")){
			result = AssertOperator.LESS_EQUAL;
		}
		return result;
	}
	
	/**
	 * Convert an operator into the appropriate text
	 * @param op operator
	 * @return the resulting text
	 */
	public static String inverseConvert(AssertOperator op){
		switch (op){
			case DISTINCT: return "<>";
			case EQUAL: return "=";
			case GREATER: return ">";
			case GREATER_EQUAL: return ">=";
			case LESS: return "<";
			case LESS_EQUAL: return "<=";
			default: return op.toString();
		}
	}	
}
